/*
 * @Author: 大D
 * @email: 857216393@qq.com
 * @Date: 2024-01-15 18:01:12
 * @Description: 用户信息  加密存储
 */
import { ref } from 'vue';
import { defineStore } from 'pinia';
import type { IUser } from '@/apis/type';
// 加密缓存
import { st } from './index';

export const useUserStore = defineStore(
  'userStore',
  () => {
    const user = ref({} as IUser);
    const setUser = (obj: IUser) => {
      user.value = obj;
    };
    const getUser = (): IUser => {
      return user.value;
    };
    const getToken = () => {
      return user.value.token;
    };
    const removeToken = () => {
      user.value.token = '';
    };
    return { user, getUser, setUser, getToken, removeToken };
  },
  // { persist: true }
  {
    persist: {
      key: 'userStore',
      storage: st
    }
  }
);
